package com.ld.security.common.mybatis.base.vo;

import com.ld.security.common.core.base.SuperVo;
import com.ld.security.common.core.exception.SuperException;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 包装容器类
 * @param <E>
 */
@Data
public class DataVo<E> implements SuperVo {

    @ApiModelProperty("数据源")
    private E data;



    @ApiModelProperty("状态")
    private int code = 200;

    @ApiModelProperty("消息")
    private String message = "";

    public DataVo() {

    }

    public DataVo(E data) {
        this.data = data;
    }

    public static <E>  DataVo<E> of(E data){
        return new DataVo(data);
    }

    public static <E>  DataVo<E> ofMsg(String msg){
        DataVo vo =  new DataVo();
        vo.setMessage(msg);
        return vo;
    }
    public static <E>  DataVo<E> of(){
        return new DataVo();
    }
    public static <E>  DataVo<E> of400(Object data){
        DataVo v =  new DataVo();
        v.setData(data);
        v.setCode(400);
        return v;
    }
    public void throwEx(){
        if(code != 200){
            throw new SuperException(this.message);
        }
    }
}
